# ========== check if run as admin ==========
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator."
    exit 1
}

# ========== allow script ==========
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

$applistdir = "./applist"

# ========== get scoop ==========
if (-not (Get-Command "scoop" -ErrorAction SilentlyContinue)) {
    try {
        Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
    }
    catch {
        Write-Warning "Failed to install scoop, please install scoop manually."
    }
}

# ========== install scoop apps ==========
if (Get-Command "scoop" -ErrorAction SilentlyContinue) {
    scoop import "$applistdir/scoop-apps.json" 
}

# ========== install winget apps ==========
if (Get-Command "winget" -ErrorAction SilentlyContinue) {
    winget import "$applistdir/winget-apps.json" 
}
else {
    Write-Warning "winget is not installed, please install winget manually."
}